package com.tlias.controller;

import com.tlias.jwt.service.JwtEmpService;
import com.tlias.jwt.service.TokenService;
import com.tlias.pojo.Emp;
import com.tlias.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    @Autowired
    TokenService tokenService;
    @Autowired
    JwtEmpService jwtEmpService;
    /**
     * 登录
     *
     * @param emp
     * @return
     */
    @PostMapping("/login")
    public Result loginByPwd(@RequestBody Emp emp) {

        Emp rEmp;
        rEmp  = jwtEmpService.getUser(emp.getUsername(), emp.getPassword());
        if (rEmp != null) {
            return Result.success(tokenService.getToken(emp));
        }
        return Result.error("登录失败");
    }
}
